<template>
  <SzCrudSingle ref="refSzCrudSingle" :cellClassName="cellClassName"
                :crm-type="crmType"
                :create-type="crmType"
                addBtnText="新建客户"
                search-place-holder="请输入客户名称/手机/电话">
  </SzCrudSingle>
</template>

<!--todo whf 需要等待customer改造后，再来调整seas-->
<script setup>

import SzCrudSingle from "/src/views/crm/componentsNew/SzCrud/SzCrud.vue";
import {floatAdd} from "utils";
import {useNumberHook} from "@/hooks/useNumberHook.js";

defineOptions({
  /** 客户管理 的 产品列表 */
  name: 'SeacIndex',
})


const crmType = ref('customer')

const {separator} = useNumberHook();
/**
 * 通过回调控制class
 */
function cellClassName({row, column, rowIndex, columnIndex}) {
  if (column.property === 'businessName') {
    return 'can-visit--underline can-visit--bold'
  } else if (column.property === 'customerName') {
    return 'can-visit--underline'
  } else {
    return ''
  }
}

const refSzCrudSingle = ref()
const moneyPageData = computed(() => {
  if (!refSzCrudSingle.value) {
    return
  }
  // 选择数据，隐藏金额信息
  console.log("refSzCrudSingle.value",refSzCrudSingle.value)
  if (refSzCrudSingle.value.config.isSelect) {
    return false
  }

  if (refSzCrudSingle.value.elTableOption.selectionList.length == 0) {
    // 如果没有选择，就显示全部的数据
    let money = 0.0
    let dataList = refSzCrudSingle.value.fieldAndListOption.dataList
    for (let index = 0; index < dataList.length; index++) {
      const element = dataList[index]
      money = floatAdd(money, parseFloat(element.money))
    }
    return {
      businessSumMoney: money.toFixed(2)
    }
  } else {
    // 如果选择了列表，则计算选中的列表
    let money = 0.0
    for (let index = 0; index < refSzCrudSingle.value.elTableOption.selectionList.length; index++) {
      const element = refSzCrudSingle.value.elTableOption.selectionList[index]
      money = floatAdd(money, parseFloat(element.money))
    }
    return {
      businessSumMoney: money.toFixed(2)
    }
  }
})

</script>


<style lang="scss" scoped>
@import '../styles/table';
</style>
